var express = require('express');
var router = express.Router();
var mongo = require('./db');
var mongodb = require('mongodb');
var ObjectId = mongodb.ObjectId;

/* GET users listing. */
router.get('/', function(req, res, next) {
  res.send('respond with a resource');
});
// 添加接口
router.post('/adds',function(req,res){
  var obj={
    pname:req.body.pname,
    leibie:req.body.leibie,
    oldPrice:req.body.oldPrice,
    price:req.body.price,
    isRed:req.body.isRed,
    shu:req.body.shu
  }
  mongo('add','list',obj,function(){
    res.send({success:'添加成功'})
  })
})

// 查询接口：
router.get('/finds',function(req,res){
  mongo('find','list',{},function(data){
    res.send({success:'查询成功',data:data})
  })
})

// 查询接口2：
router.post('/finds',function(req,res){
  mongo('find','list',{leibie:req.body.leibie},function(data){
    res.send({success:'查询成功',data:data})
  })
})

// 删除接口：
router.post('/dels',function(req,res){
  mongo('del','list',{_id:ObjectId(req.body.id)},function(){
    res.send({success:'删除成功'})
  })
})


module.exports = router;
